#include "../../mqServer/mq_queue.hpp"
#include <gtest/gtest.h>

using namespace mq;

mq::MsgQueueManager::manager_ptr msgq;

class MsgQueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        cout << "所有单元测试前执行环境初始化" << endl;
        msgq = make_shared<MsgQueueManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        cout << "所有单元测试后执行环境清理" << endl;
        // msgq->clear();
    }
};

TEST(queue_test, insert_test)
{
    unordered_map<string, string> args = {{"k1", "v1"}, {"k2", "v2"}};
    // unordered_map<string, string> args;
    msgq->declareMsgQueue("queue1", true, true, false, args);
    msgq->declareMsgQueue("queue2", true, true, false, args);
    msgq->declareMsgQueue("queue3", false, false, true, args);
    msgq->declareMsgQueue("queue4", false, true, false, args);
    ASSERT_EQ(msgq->size(), 4);
}

TEST(queue_test, remove_test)
{
    msgq->deleteMsgQueue("queue4");
    ASSERT_EQ(msgq->size(), 3);
    ASSERT_EQ(msgq->exists("queue4"), false);
}

TEST(queue_test, select_test)
{
    q_ptr queue = msgq->selectMsgQueue("queue2");
    ASSERT_NE(queue.get(), nullptr);
    ASSERT_EQ(queue->_name, "queue2");
    ASSERT_EQ(queue->_exclusive, true);
    ASSERT_EQ(queue->_durable, true);
    ASSERT_EQ(queue->_auto_delete, false);
    // ASSERT_EQ(queue->getArgs(), string("k2=v2&k1=v1"));
    cout << queue->getArgs() << endl;
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MsgQueueTest);
    RUN_ALL_TESTS();
    return 0;
}